
***********
* SETUP
***********

gl code 	 " "	// Put the three folders (PSIDload, PSIDprep, PSIDresults) here

gl downloads "  " // put raw packaged PSID downloaded data here
gl psidcode  "  " // put PSID-provided Stata code files to create .dta files here
gl rawdata   "  " // raw PSID data converted to STATA format will be saved here

gl projdata   "  " // analysis sample datasets produced from raw data will be saved here
gl us_results "  " // All US results .dta files will be saved here
gl tabfig 	  "  " // All tables and figures produced will be saved here

*Put Swedish .dta results files in this directory:
gl swe_results " "
 

/* additional user-written commands needed:
"binscatter" command: ssc install binscatter
"svmat2" command: findit svmat2, then click dm79 from http://www.stata.com/stb/stb56
"texsave" command: ssc install texsave
"renvars" command: findit renvars, then click dm88_1 from http://www.stata-journal.com/software/sj5-4
*/


******************************************************************
* PSIDload - Get RAW PSID data
******************************************************************
*Extracts PSID packaged data download and create single huge raw dataset
do ${code}/PSIDload/LOADFILES.do
do ${code}/PSIDload/extract.do
do ${code}/PSIDload/m_psid.do



******************************************************************
* PSIDprep - Create analysis dataset for project
******************************************************************
*Create analysis samples from compiled raw PSID data
do ${code}/PSIDprep/1_individual-clean.do
do ${code}/PSIDprep/2_child-parent-linked-IDs.do
do ${code}/PSIDprep/3_child-parent-merge.do
do ${code}/PSIDprep/4a_analysis-sample-long.do
do ${code}/PSIDprep/4b_analysis-sample.do


******************************************************************
* PSIDresults - Analysis/Results based only on US data
******************************************************************
*Generate all US results for the main text and appendix

* Trends analyses (dta file and actual US Figures 1-4)
do ${code}/PSIDresults/fig1to4_us.do 

* Assortative mating (Figure 5)
do ${code}/PSIDresults/fig5_us.do 

* Descriptive statistics (US dta file for Table 1)
do ${code}/PSIDresults/US_descr_byperiod.do

* Main decomposition (US dta files for Figures 6-7)
gl yrmin=1985
gl yrmax=1995
do ${code}/PSIDresults/US_model_5b_sequential_parent_AM.do  	// maternal IRP
do ${code}/PSIDresults/US_model_5bF_sequential_parent_AM.do		// paternal IRP
do ${code}/PSIDresults/US_model_5bavg_sequential_parent_AM.do	// parental IRP
gl yrmin=2008
gl yrmax=2018
do ${code}/PSIDresults/US_model_5b_sequential_parent_AM.do
do ${code}/PSIDresults/US_model_5bF_sequential_parent_AM.do
do ${code}/PSIDresults/US_model_5bavg_sequential_parent_AM.do

* Main decomposition model for employment transmission to daughters (US dta files for Figure 8)
gl yrmin=1985
gl yrmax=1995
do ${code}/PSIDresults/US_model_5b_daughters_empu.do
do ${code}/PSIDresults/US_model_5b_daughters_empxb.do
gl yrmin=2008
gl yrmax=2018
do ${code}/PSIDresults/US_model_5b_daughters_empu.do
do ${code}/PSIDresults/US_model_5b_daughters_empxb.do

* Causal vs measurement error (US dta files for Table 2)
do ${code}/PSIDresults/US_irps_causal_vs_me_OLS.do
do ${code}/PSIDresults/US_irps_causal_vs_me_incomesIV.do
do ${code}/PSIDresults/US_irps_causal_vs_me_eduempIV.do


*** APPENDICES
* Appendix A (US tables and figures)
do ${code}/PSIDresults/appendixA_tabfig_us.do 
* Appendix B decomposition (US dta files for simple model)
gl yrmin=1985
gl yrmax=1995
do ${code}/PSIDresults/US_model_2b_sequential_parent-only.do
do ${code}/PSIDresults/US_model_2bF_sequential_parent-only.do
gl yrmin=2008
gl yrmax=2018
do ${code}/PSIDresults/US_model_2b_sequential_parent-only.do
do ${code}/PSIDresults/US_model_2bF_sequential_parent-only.do


******************************************************************
* Tables/Figures that also use SWE results files
******************************************************************
*Create remaining figures and tables in the main text and appendices that draw on results files from both Sweden and the US

* Tables 1, 2 and Figures 6, 7, 8
do ${code}/PSIDresults/tab1to2_fig6to8_us_swe.do

* Appendix B (combined US-SWE tables and figures)
do ${code}/PSIDresults/appendixB_tabfig_us_se.do 

